package com.tac.controller;

import com.tac.common.result.Result;
import com.tac.pojo.Category;
import com.tac.pojo.vo.Page;
import com.tac.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
@CrossOrigin
@Api(value = "分类管理",tags ="分类管理" )
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 添加分类
     * @param category
     * @return
     */
    @ApiOperation("添加分类")
    @PostMapping("/insert")
    public Result insert(@RequestBody Category category){
        return categoryService.insert(category);
    }
    /**
     * 删除分类 判断下面有没有商品
     * @param id
     * @return
     */
    @ApiOperation("删除分类")
    @DeleteMapping("/remove")
    public Result remove(Integer id){
       return categoryService.remove(id);
    }

    /**
     * 更新分类
     * @param category
     * @return
     */
    @ApiOperation("更新分类")
    @PutMapping("/updateById")
    public Result updateById(@RequestBody Category category){
        return categoryService.updateById(category);
    }
    /**
     * 查询所有分类
     * @return
     */
    @ApiOperation("分页查询所有分类")
    @GetMapping("/selectAll")
    public Result<Page<List<Category>>> selectAll(int page , int limit){
        Result<Page<List<Category>>> pageResult = categoryService.selectAll(page, limit);
        return pageResult;
    }
    /**
     * 分级查询所有
     * @return
     */
    @ApiOperation("分级查询所有")
    @GetMapping("/selectAllByLevel")
    public Result<List<Category>> selectAllByLevel(){
       return categoryService.selectAllByLevel();
    }

}
